package com.club.football.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.club.football.dto.PageDto;
import com.club.football.dto.ScheduleSaveDto;
import com.club.football.entity.Coach;
import com.club.football.entity.Schedule;
import com.club.football.req.SchedulePageReq;
import com.club.football.service.ScheduleService;
import com.club.football.utils.R;
import com.club.football.vo.SchedulePageVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.club.football.common.CommonConstants.DEL_OK_MSG;
import static com.club.football.common.CommonConstants.GET_INFO_OK;

/**
 * 赛程Controller
 *
 * @author 1
 * @date 2023/12/28
 */
@RestController
@RequestMapping("/schedule")
public class ScheduleController {
    @Resource
    private ScheduleService scheduleService;

    @GetMapping("/page")
    public R<Page<SchedulePageVo>> page(PageDto<Schedule> pageDto, SchedulePageReq schedulePageReq) {
        return scheduleService.schedulePage(pageDto, schedulePageReq);
    }

    /**
     * 赛程保存
     *
     * @return {@link R}<{@link String}>
     */
    @PostMapping("/save")
    public R<String> save(@RequestBody @Valid ScheduleSaveDto saveDto) {
        return scheduleService.scheduleSave(saveDto);
    }

    /**
     * 删除
     *
     * @param id ID
     * @return {@link R}<{@link String}>
     */
    @DeleteMapping("/remove/{id}")
    public R<String> remove(@PathVariable Long id) {
        scheduleService.removeById(id);
        return R.ok(DEL_OK_MSG);
    }


    /**
     * 信息
     *
     * @param id ID
     * @return {@link R}<{@link Coach}>
     */
    @GetMapping("/info/{id}")
    public R<Schedule> info(@PathVariable Long id) {
        return R.ok(scheduleService.getById(id), GET_INFO_OK);
    }
}
